package kr.co.m2soft.container
{
	import kr.co.m2soft.draw.DMDraw;
	import kr.co.m2soft.draw.EPDraw;
	import kr.co.m2soft.draw.LLDraw;
	import kr.co.m2soft.draw.LNDraw;
	import kr.co.m2soft.draw.PODraw;
	import kr.co.m2soft.draw.RADraw;
	import kr.co.m2soft.draw.SCDraw;
	import kr.co.m2soft.model.page.PG;
	import kr.co.m2soft.model.page.elements.DM;
	import kr.co.m2soft.model.page.elements.EP;
	import kr.co.m2soft.model.page.elements.LL;
	import kr.co.m2soft.model.page.elements.LN;
	import kr.co.m2soft.model.page.elements.PO;
	import kr.co.m2soft.model.page.elements.RA;
	import kr.co.m2soft.model.page.elements.SC;
	
	import mx.core.ClassFactory;
	
	import spark.components.BorderContainer;
	import spark.components.Group;
	import spark.primitives.Rect;
	
	import utils.commonUtils;
	
	public class PGContainer extends Group
	{
		private var _dataProvider:PG;
		
		public function PGContainer()
		{
			super();
		}
		
		public function draw():void
		{
			var o:*;
			var cf:ClassFactory;
			for each(var item:* in _dataProvider.elements){
				cf = null;
				if(item is LN){
					cf = new ClassFactory(LNDraw);
				}else if(item is SC){
					cf = new ClassFactory(SCDraw);
				}else if(item is LL){
					cf = new ClassFactory(LLDraw);
				}else if(item is EP){
					cf = new ClassFactory(EPDraw);
				}else if(item is DM){
					cf = new ClassFactory(DMDraw);
				}else if(item is RA){
					cf = new ClassFactory(RADraw);
				}else if(item is PO){
					cf = new ClassFactory(PODraw);
				}
					
				
				
				if(cf){
					o = cf.newInstance();
					o.target = this;
					o.model = item;
					o.draw();
				}
			}
		}
		
		override protected function initializationComplete():void
		{
			super.initializationComplete();
			
			graphics.beginFill(0xFFFFFF,1);
			graphics.lineTo(0,0);
			graphics.lineTo(width,0);
			graphics.lineTo(width,height);
			graphics.lineTo(0,height);
			graphics.lineTo(0,0);
			graphics.endFill();
			
		}
		
		override public function set width(value:Number):void
		{
			super.width = commonUtils.inchesToPixels(value);
		}
		
		override public function set height(value:Number):void
		{
			super.height = commonUtils.inchesToPixels(value);
		}

		public function get dataProvider():PG
		{
			return _dataProvider;
		}

		public function set dataProvider(value:PG):void
		{
			_dataProvider = value;
		}

	}
}